import { defineStore } from "pinia";

interface Area {
  name: string;
  x: number;
  y: number;
  valueNewTemp: number;
  valueNewHumidity: number;
  oocTemp: boolean;
  oocHumidity: boolean;
}

export const useFabStore = defineStore("fab", {
  state: () => ({
    areas: [
      {
        name: "WST",
        x: 0.2,
        y: 0.8,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "LITHO",
        x: 0.4,
        y: 0.8,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "GPVD",
        x: 0.5,
        y: 0.8,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "CVD",
        x: 0.7,
        y: 0.8,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "CMP",
        x: 0.1,
        y: 0.6,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "PVD",
        x: 0.5,
        y: 0.6,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "RTP",
        x: 0.7,
        y: 0.6,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "EPI",
        x: 0.1,
        y: 0.35,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "GCMP",
        x: 0.2,
        y: 0.35,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "ETCH",
        x: 0.4,
        y: 0.35,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "WET",
        x: 0.6,
        y: 0.35,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      },
      {
        name: "DIFF",
        x: 0.7,
        y: 0.35,
        valueNewTemp: 0,
        valueNewHumidity: 0,
        indicatorTemp: "",
        valueMaxTemp: 0,
        valueMinTemp: 0,
        valueAvgTemp: 0,
        oocTemp: false,
        indicatorHumidity: "",
        valueMaxHumidity: 0,
        valueMinHumidity: 0,
        valueAvgHumidity: 0,
        oocHumidity: false
      }
    ] as Area[]
  }),

  actions: {
    updateAreas(newAreas: Partial<Area>[]) {
      newAreas.forEach(newArea => {
        const index = this.areas.findIndex(a => a.name === newArea.name);
        if (index !== -1) {
          this.areas[index] = { ...this.areas[index], ...newArea };
        }
      });
    }
  }
});
